package com.qf.application.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.application.commons.utils.R;
import com.qf.application.entity.Role;
import com.qf.application.service.IRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @PostMapping("/page")
    public R page(@RequestBody Page<Role> page) {
        log.debug("后端接收到了前端的请求");
        return R.ok(roleService.page(page));
    }

    @GetMapping("/list")
    public R list() {
        return R.ok(roleService.list());
    }

    @PostMapping("/save")
    public R save(@RequestBody Role role) {
        role.setCreateTime(new Date());
        return R.write(roleService.save(role));
    }

    @PostMapping("/update")
    public R update(@RequestBody Role role) {
        return R.write(roleService.updateById(role));
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Integer id) {
        return R.ok(roleService.getById(id));
    }

    @PostMapping("/remove")
    public R remove(@RequestBody List<Integer> ridList) {
        return R.write(roleService.removeBatchByIds(ridList));
    }

}
